package cn.edu.neusoft.yuejian4.yuejian_4.activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import cn.edu.neusoft.yuejian4.yuejian_4.R;
import cn.edu.neusoft.yuejian4.yuejian_4.javaBean.Recentgame;
import cn.edu.neusoft.yuejian4.yuejian_4.listener.TListener;
import cn.edu.neusoft.yuejian4.yuejian_4.model.GameModel;

/**
 * Created by Lix on 2018/10/18.
 */

public class GameDetailActivity extends AppCompatActivity implements View.OnClickListener {
    private ImageView back;
    private TextView gamename;
    private WebView webView;
    private SharedPreferences sp;
    private int uid,gid;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_game_detail);
        initView();
        initEvent();
        sp = getSharedPreferences("userinfo",MODE_PRIVATE);
        gid = getIntent().getIntExtra("game_id",1);
        uid = sp.getInt("uid",4);
        GameModel gameModel = new GameModel();
        gameModel.getGame(gid,getGameListener);
    }
    TListener<Recentgame> getGameListener = new TListener<Recentgame>() {
        @Override
        public void onResponse(Recentgame recentgame) {
            gamename.setText(recentgame.getName());
            webView.loadUrl(recentgame.getIntro());
        }

        @Override
        public void onFail(String msg) {

        }
    };
    private void initView(){
        webView = (WebView)findViewById(R.id.game_web_view);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new WebViewClient());
        back = (ImageView)findViewById(R.id.game_detail_back);
        gamename = (TextView)findViewById(R.id.game_detail_name);
    }
    private void initEvent(){
        back.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.game_detail_back:
                finish();
                break;
        }
    }
}
